package com.wzcl.app.model.vo;

import com.wzcl.app.dao.model.TopicInfo;
import com.wzcl.app.model.common.WZCL;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Data
public class TopicInfoVo extends BaseVo {

    @ApiModelProperty(value = "题目类型")
    private Integer type;
    private String typeStr;

    @ApiModelProperty(value = "题目")
    private String  branch;

    @ApiModelProperty(value = "题目答案")
    private String  answer;

    @ApiModelProperty(value = "答案解析")
    private String  analysis;

    @ApiModelProperty(value = "分值")
    private Integer score;

    @ApiModelProperty(value = "排序字段")
    private Integer orderNo;

    @ApiModelProperty(value = "选项")
    private List<TopicOptionVo> topicOptionList;

    private TopicInfoVo(){}

    public static TopicInfoVo create(TopicInfo topicInfo){
        TopicInfoVo topicInfoVo = new TopicInfoVo();
        BeanUtils.copyProperties(topicInfo,topicInfoVo,"topicOptionList");
        if(topicInfo.getOptionList() != null && topicInfo.getOptionList().size()>0){
            topicInfoVo.topicOptionList = topicInfo.getOptionList().stream().map(TopicOptionVo::create).collect(Collectors.toList());
        }
        topicInfoVo.translationValueStr();
        return topicInfoVo;
    }

    @Override
    public void translationValueStr() {
        Map<String, Map<Integer, String>> map = getTranslationMap();
        this.typeStr = map.get(WZCL.GROUP_NAME.TOPIC_TYPE).get(this.type);
    }

    @Override
    public void processResources() {

    }
}
